#include "iomanager.h"

IOManager::IOManager()
{
    QObject::connect(&this->_xmiReader, SIGNAL(finished(UmlProject*,DatatypeDictionary*)), this, SLOT(readerIsFinished(UmlProject*,DatatypeDictionary*)));
}

void IOManager::loadProject(QString filePath)
{
    this->_xmiReader.setFilePath(filePath);
    this->_xmiReader.setIsWMI(true);
    this->_xmiReader.run();
}

void IOManager::saveProject(UmlProject *project)
{
    this->_xmiWriter.setUmlProject(project);
    this->_xmiWriter.setIsWMI(true);
    this->_xmiWriter.run();
}

void IOManager::exportXMI(UmlProject *project, QString filePath)
{
    this->_xmiWriter.setUmlProject(project);
    this->_xmiWriter.setIsWMI(false);
    this->_xmiWriter.setFilePath(filePath);
    this->_xmiWriter.run();
}

void IOManager::importXMI(QString filePath)
{
    this->_xmiReader.setFilePath(filePath);
    this->_xmiReader.setIsWMI(false);
    this->_xmiReader.run();
}

void IOManager::exportToJava(UmlProject *project, QString filePath)
{
    this->_javaWriter.setUmlProject(project);
    this->_javaWriter.setFilePath(filePath);
    this->_javaWriter.run();
}

void IOManager::setMainWindow(MainWindow *mainWindow)
{
    this->_mainWindow = mainWindow;
}

void IOManager::readerIsFinished(UmlProject *project, DatatypeDictionary *dataTypes)
{
    project->setMainWindow(this->_mainWindow);
    project->setDataTypes(dataTypes);
}
